/*--------------------------------------------------------------------
 * File name: sturct_header.h
 * Author: 刘长达      Version:   1.0     Date:
 * Description: 主要为创建解析数据模块所需要的结构体
 * Contents:
 *--------------------------------------------------------------------*/
/*--------------------------------------------------------------------
 *                          文件更新和维护记录
 * Author:	刘长达
 * Date:	2019.11.9
 * Contents: 创建并维护结构体 mbsys_depth_struct
 * Date:	2019.11.22
 * Contents: 维护结构体 depth\seabed\heading\postion\runtime
 *
 *--------------------------------------------------------------------*/

#ifndef STRUCT_HEADER
#define STRUCT_HEADER
#define MBSYS_MAXBEAMS 1024

struct mbsys_depth_struct {
    unsigned int depth_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==44h
    unsigned int EM_model;
    unsigned int depth_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int depth_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int depth_ping_count;	// 0-65535
    unsigned int depth_sys_serial;	// 100-
    unsigned int depth_heading; 	// 0-35999 in 0.01°
    unsigned int depth_ssv;	// 14000-16000 dm/s
    unsigned int depth_transmit_depth;	// 0-65535
    unsigned int depth_beams_max;	// 48-
    unsigned int depth_N;	// 1-254 number of valid beams
    unsigned int depth_Zresoulation;	// 1-254 depth resolution (0.01 m)
    unsigned int depth_XYresoulation;  // 1-254 depth resolution (0.01 m)
    unsigned int depth_HZsampling;	/* 300-30000 number of sampling
                    rate in HZ  sampling rate (Hz) OR depth difference between
                    sonar heads in EM3000D - -32768 to 32766 */
    short depth_transmit_N[MBSYS_MAXBEAMS];  // usually use this
    unsigned int depth_120and300_transmit_N[MBSYS_MAXBEAMS]; /* For 120 and 300
                     is unsigned 1-65534 */
    short depth_acrosstrack_N[MBSYS_MAXBEAMS]; /* -32768 to 32766
                    acrosstrack distances in distance resolution units */
    short depth_alongtrack_N[MBSYS_MAXBEAMS]; /* -32768 to 32766
                    acrosstrack distances in distance resolution units */
    short depth_depression_N[MBSYS_MAXBEAMS]; // -11000 to 11000
    unsigned int depth_azimuth_N[MBSYS_MAXBEAMS]; // 0-56999
    unsigned int depth_range_N[MBSYS_MAXBEAMS]; // 0-65534
    unsigned int depth_quality_N[MBSYS_MAXBEAMS]; // 0-254
    unsigned int depth_detection_window[MBSYS_MAXBEAMS];/* 1-254
                    samples/4 */
    short depth_reflectivity_N[MBSYS_MAXBEAMS]; /* -128 to 126 in0.5 dB
                    resolution Example: -20 dB = 216 */
    unsigned int depth_beam_num[MBSYS_MAXBEAMS]; // 1-254
    short depth_offset_multiplier;  //-1 to 17
    unsigned int ETX;	// always==03h
    unsigned int check;	// Check sum of data between STX and ETX
};
struct mbsys_xyz_struct {
    unsigned int xyz_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==58h
    unsigned int EM_model;
    unsigned int xyz_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int xyz_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int xyz_ping_count;	// 0-65535
    unsigned int xyz_sys_serial;	// 100-
    unsigned int xyz_heading; 	// 0-35999 in 0.01°
    unsigned int xyz_ssv;	// 14000-16000 dm/s
    float xyz_transmit_depth;	// 0-65535
    unsigned int xyz_N;	// 1-1024
    unsigned int xyz_valid_detection;  // 1-1024
    float xyz_HZsampling;	/* 300-30000 number of sampling
                    rate in HZ  sampling rate (Hz) OR depth difference between
                    sonar heads in EM3000D - -32768 to 32766 */
    unsigned int xyz_Scanning;
    unsigned int xyz_Spare;
    float xyz_depth_N[MBSYS_MAXBEAMS];  // usually use this
    float xyz_acrosstrack_N[MBSYS_MAXBEAMS];
    float xyz_alongtrack_N[MBSYS_MAXBEAMS];
    unsigned int xyz_detection_window_N[MBSYS_MAXBEAMS];
    unsigned int xyz_quality_N[MBSYS_MAXBEAMS]; // 0-254
    short xyz_IBA_N[MBSYS_MAXBEAMS]; // -128-126
    unsigned int xyz_detection_info[MBSYS_MAXBEAMS];
    short int xyz_time_cleaning[MBSYS_MAXBEAMS];
    short xyz_BS_resloution[MBSYS_MAXBEAMS];

    unsigned int Spare;	// always==00h
    unsigned int ETX;	// always==03h
    unsigned int check;	// Check sum of data between STX and ETX
};
struct mbsys_seabed_struct {
    unsigned int seabed_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==53h
    unsigned int EM_model;
     unsigned int  	seabed_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int 	seabed_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int 	seabed_count;	// 0-65535
    unsigned int 	seabed_serial;	// 100-
    unsigned int  seabed_absorption; // 1-20000
    unsigned int  seabed_pluse_len; // 50-
    unsigned int  seabed_range_samples; //1-16384
    unsigned int  seabed_range_TVG_start; //0-16384
    unsigned int  seabed_range_TVG_stop; //0-16384
    short seabed_BSN; // -50 TO 10
    short seabed_BSO; // -60 TO 0
    unsigned int  seabed_beamwidth_TX; // 1-300
    unsigned int  seabed_crossover_TVG; //20-300
    unsigned int  seabed_N; //1-254

    unsigned int  seabed_beam_index_N[MBSYS_MAXBEAMS]; //这样能行吗？0-253
    short seabed_direction_N[MBSYS_MAXBEAMS]; // -1 or 1
    unsigned int seabed_Ns_N[MBSYS_MAXBEAMS]; // 1-
    unsigned int seabed_centre_num_N[MBSYS_MAXBEAMS]; // 1-
    unsigned int count_NS;
    short seabed_ampulitudes_NS[MBSYS_MAXBEAMS * 10]; // -128 to 126

    unsigned int  seabed_spare; // 0 if used
    unsigned int ETX;	// always==03h
    unsigned int check;	// Check sum of data between STX and ETX
};
struct mbsys_range78_struct {
    unsigned int range78_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==4eh
    unsigned int EM_model;
    unsigned int range78_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int range78_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int range78_ping_count;	/* sequential counter or input identifier */
    unsigned int range78_serial;	/* 100- */
    unsigned int range78_ssv; // 14000 - 16000
    unsigned int range78_ntx; // 1-
    unsigned int range78_nrx; // 1-
    unsigned int range78_detection_num; // 1-
    float range78_sample_hz;
    unsigned int range78_dscale;

    short range78_angleTX_Ntx[MBSYS_MAXBEAMS*2]; // -2900 - 2900
    unsigned int range78_range_focus_Ntx[MBSYS_MAXBEAMS*2]; // 0-65534 0 = No focusing applied
    float range78_signal_len_Ntx[MBSYS_MAXBEAMS*2];
    float range78_transmit_sector_TX_Ntx[MBSYS_MAXBEAMS*2];
    float range78_centre_hz_Ntx[MBSYS_MAXBEAMS*2];
    unsigned int range78_absorption_Ntx[MBSYS_MAXBEAMS*2];
    unsigned int range78_signal_waveform_Ntx[MBSYS_MAXBEAMS*2]; // 0-99
    unsigned int range78_transmit_TX_Ntx[MBSYS_MAXBEAMS*2];
    float range78_bandwidth_hz_Ntx[MBSYS_MAXBEAMS*2];

    short range78_anlge_RX_Nrx[MBSYS_MAXBEAMS*2]; //-11000 to 11000
    unsigned int range78_transmit_sector_num_Nrx[MBSYS_MAXBEAMS*2];
    unsigned int range78_detection_info_Nrx[MBSYS_MAXBEAMS*2];
    unsigned int range78_detection_len_Nrx[MBSYS_MAXBEAMS*2];
    unsigned int range78_quality_Nrx[MBSYS_MAXBEAMS*2]; // 0-254
    short range78_Dcorr_Nrx[MBSYS_MAXBEAMS*2];
    float range78_two_times_Nrx[MBSYS_MAXBEAMS*2];
    short range78_Reflectivity_Nrx[MBSYS_MAXBEAMS*2];
    short range78_clean_time_Nrx[MBSYS_MAXBEAMS*2];
    unsigned int range78_Spare_Nrx[MBSYS_MAXBEAMS*2];
    unsigned int Spare;	// always==00h
    unsigned int ETX;	// always==03h
    unsigned int check;	// Check sum of data between STX and ETX
};
struct mbsys_rangef_struct {
    unsigned int rangef_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==66h
    unsigned int EM_model;
    unsigned int rangef_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int rangef_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int rangef_ping_count;	/* sequential counter or input identifier */
    unsigned int rangef_serial;	/* 100- */
    unsigned int rangef_Ntx; // 1-20
    unsigned int rangef_N; // 1-1999
    unsigned int rangef_SamplingHZ; // 100 to 100000 * 100
    short rangef_ROV; // in 0.01m
    unsigned int rangef_ssv; // 14000-16000
    unsigned int rangef_maxbeam_possi; // 1-1999
    unsigned int Spare1; //
    unsigned int Spare2; //

    short rangef_angleTX_Ntx[20]; // -2900 - 2900
    unsigned int rangef_focus_Ntx[20]; // 0-65535 0 = No focusing applied
    unsigned int rangef_signal_len_Ntx[20];
    unsigned int rangef_timeoff_Ntx[20];
    unsigned int rangef_centre_hz_Ntx[20];
    unsigned int rangef_bandwidth_hz_Ntx[20]; //1-65535
    unsigned int rangef_signal_waveform_Ntx[20]; // 0-99
    unsigned int rangef_transmit_sector_Ntx[20]; // 0-99

    short rangef_anlge_RX_N[MBSYS_MAXBEAMS*2]; //-11000 to 11000
    unsigned int rangef_R_N[MBSYS_MAXBEAMS*2]; // 0- 65535
    unsigned int rangef_transmit_sector_num_N[MBSYS_MAXBEAMS*2]; //0 to 19
    short rangef_Reflectivity_N[MBSYS_MAXBEAMS*2]; // -128 to 127
    unsigned int rangef_quality_N[MBSYS_MAXBEAMS*2]; // 0-254
    unsigned int rangef_detection_len_N[MBSYS_MAXBEAMS*2]; //1-254
    short rangef_beam_number_N[MBSYS_MAXBEAMS*2]; //-1999 to 1999

    unsigned int Spare;	// always==00h
    unsigned int ETX;	// always==03h
    unsigned int check;	// Check sum of data between STX and ETX
};
struct mbsys_heading_struct {
    unsigned int heading_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==48h
    unsigned int EM_model;
    unsigned int heading_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int heading_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int heading_count;	// 0-65535
    unsigned int heading_serial;	// 100-
    unsigned int heading_N;	// 1-
    unsigned int heading_msecN[MBSYS_MAXBEAMS]; // 0-65534
    unsigned int headingN[MBSYS_MAXBEAMS]; // 0-35999
    unsigned int heading_indicator; // (active or not) (0 = inactive)
    unsigned int ETX; //always == 03h
    unsigned int check;
};
struct mbsys_position_struct {
    unsigned int position_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==50h
    unsigned int EM_model;
    unsigned int position_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int position_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int position_count;	// 0-65535
    unsigned int position_serial;	// 100-
    int position_latitude;	/* latitude in decimal degrees * 20000000
                    (negative in southern hemisphere)
                    if valid, invalid = 0x7FFFFFFF */
    int position_longitude;	/* longitude in decimal degrees * 10000000
                    (negative in western hemisphere)
                    if valid, invalid = 0x7FFFFFFF */
    unsigned int 	position_measure; // in cm
    unsigned int 	position_vessel_speed; // 0- cm/s
    unsigned int 	position_vessel_course; // 0-35999
    unsigned int 	position_vessel_heading; // 0-35999
    unsigned int 	position_descriptor; // 1-254
    unsigned int 	position_inputN; // -254
    short position_received; // Complete input datagram except header and tail
    unsigned int ETX; // always == 03h
    unsigned int check;
};
struct mbsys_runtime_struct {
    unsigned int runtime_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==52h
    unsigned int EM_model;
    unsigned int runtime_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int runtime_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int runtime_count;	/* 0-65535 */
    unsigned int 	runtime_serial;	/* 100- */
    unsigned int  runtime_status; // status has different signficance
    unsigned int  runtime_CPU; // status has different signficance
    unsigned int  runtime_BSP; // status has different signficance
    unsigned int  runtime_header_status; // status has different signficance
    unsigned int  runtime_mode; // 0-
    unsigned int  runtime_filter; // 0-255
    unsigned int  runtime_min; // 0-10000
    unsigned int  runtime_max; // 1-12000
    unsigned int  runtime_absorption; // 1-20000
    unsigned int  runtime_transmit_len; // 1-50000
    unsigned int  runtime_transmit_beamwidth; // 1-300
    short  runtime_transmit_power; // 0 to -50
    unsigned int  runtime_rece_beamwid; // 5-80
    unsigned int  runtime_beamwidth_hz; // 1-255
    unsigned int  runtime_mode2; // 0-50
    unsigned int  runtime_TVG; // 2-30
    unsigned int  runtime_sur_sped; // 0-3
    unsigned int  runtime_max_swath; // 10-30000
    unsigned int  runtime_space_beam; // 0-3
    unsigned int  runtime_max_cover; // 10-110
    unsigned int  runtime_yaw;
    unsigned int  runtime_max_starboard; // 10-110
    unsigned int  runtime_max_starboard_m; // 10-30000
    short  runtime_tras_along; // -300 to 300
    unsigned int runtime_durotong_sped; // 20000-25000
    unsigned int  runtime_fileter_or_hilo; // 0-255
                                                             // 0-120
    unsigned int ETX; // always == 03h
    unsigned int check;
};
struct mbsys_attitude_struct {
    unsigned int attitude_bytes;
    unsigned int STX;   //always==02h
    unsigned int Type;  //always==41h
    unsigned int EM_model;
    unsigned int attitude_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int attitude_msec;	/* time since midnight in msec
                    08:12:51.234 = 29570234 */
    unsigned int attitude_count;	/* 0-65535 */
    unsigned int attitude_serial;	/* 100- */
    unsigned int attitude_N;  //1-
    unsigned int	attitude_msectime_N[MBSYS_MAXBEAMS]; // 0 - 65534
    unsigned int	attitude_status_N[MBSYS_MAXBEAMS]; // copy from input
    short attitude_roll_N[MBSYS_MAXBEAMS]; // -18000 - 18000
    short attitude_pitch_N[MBSYS_MAXBEAMS]; // -18000 - 18000
    short attitude_heave_N[MBSYS_MAXBEAMS]; // -18000 - 18000
    unsigned int attitude_heading_N[MBSYS_MAXBEAMS]; // 0 - 35999
    unsigned int attitude_sensor_descriptor;
    unsigned int ETX;
    unsigned int cheack;
};

struct raw_depth_struct {
    unsigned int depth_date;
    unsigned int depth_msec;
    unsigned int ping_count;
    unsigned int beam_N; // 0-254
//    short depth_transmit_N[MBSYS_MAXBEAMS];
//    unsigned int depth_120and300_transmit_N[MBSYS_MAXBEAMS];
//    short depth_acrosstrack_N[MBSYS_MAXBEAMS]; //X
//    short depth_alongtrack_N[MBSYS_MAXBEAMS]; //Y
//    short depth_depression_N[MBSYS_MAXBEAMS];
//    unsigned int depth_azimuth_N[MBSYS_MAXBEAMS];
//    unsigned int depth_range_N[MBSYS_MAXBEAMS];
//    unsigned int depth_quality_N[MBSYS_MAXBEAMS];
//    unsigned int depth_detection_window[MBSYS_MAXBEAMS];
//    short depth_reflectivity_N[MBSYS_MAXBEAMS];
//    unsigned int depth_beam_num[MBSYS_MAXBEAMS];
    short depth_transmit_N[254];
    unsigned int depth_120and300_transmit_N[254];
    short depth_acrosstrack_N[254]; //X
    short depth_alongtrack_N[254]; //Y
    short Anlge_N[254]; // -11000 to 11000
    short Reflectivity_N[254]; // -128 to 127
    //short depth_depression_N[254];
//    unsigned int depth_azimuth_N[254];
//    unsigned int depth_range_N[254];
//    unsigned int depth_quality_N[254];
//    unsigned int depth_detection_window[254];
//    short depth_reflectivity_N[254];
//    unsigned int depth_beam_num[254];
};
struct raw_seabed_struct {
    unsigned int 	seabed_pingno;	// 0-65535
    unsigned int 	seabed_beam_N;
    unsigned int  seabed_beamno[254]; //这样能行吗？0-253
    unsigned int  	seabed_date;
    unsigned int 	seabed_msec;
    unsigned int count_NS[254];
    short seabed_ampulitudes_NS[254][254]; // -128 to 126
};
struct raw_install_struct {
    double install_x; // 只有第一个有效 [0]
    double install_y; // 只有第一个有效 [0]
    double install_z; // 只有第一个有效 [0]
};
struct raw_position_struct {
    double position_L;
    double position_B;
    unsigned int position_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int position_msec;
    double position_x;
    double position_y;
};
struct raw_attitude_struct {
    unsigned int attitude_date;	/* date = year*10000 + month*100 + day
                    Feb 26, 1995 = 19950226 */
    unsigned int attitude_mesc;
     unsigned int attitude_count;	/* 0-65535 */
    unsigned int attitude_msectime_N[100]; // 0 - 65534
    double attitude_heading_N[100]; // 0 - 35999
    double attitude_roll_N[100]; // -18000 - 18000
    double attitude_pitch_N[100]; // -18000 - 18000
    double attitude_heave_N[100]; // -18000 - 18000
    double attitude_heading; // 0 - 35999
    double attitude_roll; // -18000 - 18000
    double attitude_pitch; // -18000 - 18000
    double attitude_heave; // -18000 - 18000
};
struct interval_position_attitude_struct {
    unsigned int ping_count;
    unsigned int interval_position_msec; //原则上等于另一个时间
    double interval_position_x;
    double interval_position_y;
    unsigned int interval_attitude_mesc;
    double interval_attitude_heading; // 0 - 35999
    double interval_attitude_roll; // -18000 - 18000
    double interval_attitude_pitch; // -18000 - 18000
    double interval_attitude_heave; // -18000 - 18000
    double interval_ts_x;
    double interval_ts_y;
    double interval_ts_z;
    unsigned int beam_number; // 0-254
    double beam_x[254];
    double beam_y[254];
    double beam_z[254];
    double depthZ_N[254];
    double depth_120and300_transmit_N[254];
    double depthX_N[254];
    double depthY_N[254];
    short beam_Reflectivity_N[254];
};

struct bs_classify_struct {
    unsigned int Number; // 标记点号
    double X;
    double Y;
    double Z; //记录点空间位置
    short Reflectivity; //反向散射强度
    double ASM; //二阶矩
    double ENT; //熵
    double CORR; // 相关系数
    double CON; // 对比度
    short classify_number; // 分类后的所属聚类

 //*---------------暂时为了kmeans算法----------
    unsigned int bs_number;
    double bs_x;
    double bs_y;
    double bs_z;
    double BS;
    short iso_classify;
};

#endif // STRUCT_HEADER
